package com.itheima.mapper;

import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetMealDao {

    //添加套餐
    @Insert("insert into chuanzhi.t_setmeal(code,name,sex,age,helpCode,price,remark,attention,img) " +
            "values(#{code},#{name},#{sex},#{age},#{helpCode},#{price},#{remark},#{attention},#{img})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Setmeal setmeal);


    //获取所有套餐
    List<Setmeal> findAll();

    //添加套餐和检查组关系
    @Insert("insert into chuanzhi.t_setmeal_checkgroup(setmeal_id, checkgroup_id) " +
            "values(#{id},#{checkgroupIds})")
    void addSetMealAndCheckGroup(Integer id, Integer checkgroupIds);

    //根据名字查询是否套餐是否存在
    @Select("select * from chuanzhi.t_setmeal where name=#{name}")
    Setmeal findByName(String name);

    //修改套餐与检查组关系
    void insertSetMealCheckGroup(Integer  setmealId,List<Integer>checkgroupIds);

    //根据套餐id删除套餐和检查组关系
    @Delete("delete from chuanzhi.t_setmeal_checkgroup where setmeal_id=#{setMealId}")
    void deleteAssociation(Integer setMealId);

    //根据套餐id查询套餐
    @Select("select * from chuanzhi.t_setmeal where id=#{id}")
    Setmeal findById(Integer id);

    //分页查询
    @Select("select * from chuanzhi.t_setmeal")
    List<Setmeal> findPage(QueryPageBean page);

    //更新套餐
    @Update("update chuanzhi.t_setmeal set code=#{code},name=#{name},sex=#{sex},age=#{age},helpCode=#{helpCode},price=#{price},remark=#{remark},attention=#{attention},img=#{img} where id=#{id}")
    void update(Setmeal setmeal);
}
